//
//  GSCommonLoginSuccessController.m
//  GSLoginDemo
//
//  Created by guoshikeji_a on 2018/7/30.
//  Copyright © 2018年 guoshikeji. All rights reserved.
//

#import "GSCommonLoginSuccessController.h"

@interface GSCommonLoginSuccessController ()

@property (nonatomic, strong) GSCommonLoginSuccessView *loginSuccessView;

/**
 *successType
 */
@property (nonatomic, assign) GSCommonLoginSuccessType successType;

/**
 *GSCommonLoginSuccessShowComplete
 */
@property (nonatomic, copy) GSCommonLoginSuccessShowComplete showComplete;

@end

@implementation GSCommonLoginSuccessController

+ (void)showFromController:(UIViewController *)fromController succssType:(GSCommonLoginSuccessType)succssType complete:(GSCommonLoginSuccessShowComplete)showComplete{
    UIWindow *window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    window.windowLevel = UIWindowLevelAlert;
    GSCommonLoginSuccessController *vc = [GSCommonLoginSuccessController new];
    vc.showWindow = window;
    vc.successType = succssType;
    vc.showComplete = showComplete;
    window.rootViewController = vc;
    [window makeKeyAndVisible];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = GSLOGINRGBRGBHEXA(0x0C0C0C,0.31);
    [self setupSubviews];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)setupSubviews {
    self.loginSuccessView = [[GSCommonLoginSuccessView alloc] initWithSuccessType:self.successType];
    [self.view addSubview:self.loginSuccessView];
    CGFloat width = floorf(self.view.frame.size.width*(355.0/375.0));
    [self.loginSuccessView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.centerY.mas_equalTo(self.view);
        make.width.mas_equalTo(width);
    }];
    //
    CGSize size = [self.loginSuccessView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
    [self.loginSuccessView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(size.height);
    }];
    [self.view layoutIfNeeded];
    //
    [self.loginSuccessView countdownAction];
    __weak typeof(self) wself = self;
    self.loginSuccessView.countdownComplete = ^{
        [wself dismissWindow];
    };
}


- (void)dismissWindow {
    if (self.showComplete) {
        self.showComplete();
    }
    [super dismissWindow];
}

@end
